/**
 * 
 */
package org.t2.game.server.module.player.model;

import org.banish.sql.core.annotation.Column;
import org.banish.sql.core.annotation.Id;
import org.banish.sql.core.annotation.Index;
import org.banish.sql.core.annotation.Table;
import org.banish.sql.core.annotation.Id.Strategy;
import org.banish.sql.core.annotation.enuma.AsyncType;
import org.banish.sql.core.annotation.enuma.IndexType;
import org.banish.sql.core.entity.AbstractEntity;
import org.gaming.ruler.spring.Spring;
import org.gaming.service.repository.annotation.JvmCache;
import org.springframework.stereotype.Repository;
import org.t2.game.server.foundation.starting.ApplicationSettings;
import org.t2.game.server.module.data.saver.IPlayerData;

/**
 * 
 */
@Repository
@JvmCache(cacheTime = 0)
@Table(comment = "玩家信息表", dbAlias = "game", asyncType = AsyncType.UPDATE, indexs = {
		@Index(fields = { "openId", "serverId" }, type = IndexType.UNIQUE) })
public class Player extends AbstractEntity implements IPlayerData {
	@Id(strategy = Strategy.AUTO)
	@Column(comment = "玩家ID")
	private long id;
	@Column(name = "platform_id", comment = "平台ID", readonly = true)
	private int platformId;
	@Column(name = "channel_id", comment = "渠道ID", readonly = true)
	private long channelId;
	@Column(name = "server_id", comment = "服务器ID", readonly = true)
	private int serverId;
	@Column(name = "open_id", comment = "SDK账号ID", length = 50, readonly = true)
	private String openId;
	@Column(comment = "昵称")
	private String nick;
	@Column(comment = "等级")
	private long level;
	@Column(name = "vip_level", comment = "VIP等级")
	private int vipLevel;
	@Column(comment = "头像")
	private int head;
	@Column(comment = "历史充值金额，单位元")
	private long recharge;
	@Column(comment = "是否在线")
	private boolean online;
	@Column(name = "last_login_time", comment = "最后登录时间", extra = "time")
	private long lastLoginTime;
	@Column(name = "last_logout_time", comment = "最后登出时间", extra = "time")
	private long lastLogoutTime;
	@Column(name = "login_ip", comment = "登录IP", length = 50)
	private String loginIp;
	@Column(name = "forbid_end_time", comment = "封号结束时间", extra = "time")
	private long forbidEndTime;
	@Column(name = "create_ip", comment = "创号IP", length = 50, readonly = true)
	private String createIp;
	@Column(name = "device_model", comment = "设备型号")
	private String deviceModel;
	@Column(name = "create_pay", comment = "是否创号当天有充值")
	private boolean createPay;
	@Column(name = "first_pay_time", comment = "首次付费时间戳，不要用time格式")
	private long firstPayTime;
	@Column(name = "new_comer", comment = "是否新账号", readonly = true)
	private boolean newComer = true;
	@Column(comment = "通关关卡")
	private long mission;
	@Column(name = "forbid_rank_time", comment = "封榜结束时间", extra = "time")
	private long forbidRankTime;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public int getServerId() {
		return serverId;
	}

	public void setServerId(int serverId) {
		this.serverId = serverId;
	}

	public boolean isOnline() {
		return online;
	}

	public void setOnline(boolean online) {
		this.online = online;
	}

	public long getForbidEndTime() {
		return forbidEndTime;
	}

	public void setForbidEndTime(long forbidEndTime) {
		this.forbidEndTime = forbidEndTime;
	}

	public long getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(long lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public long getLastLogoutTime() {
		return lastLogoutTime;
	}

	public void setLastLogoutTime(long lastLogoutTime) {
		this.lastLogoutTime = lastLogoutTime;
	}

	public String getCreateIp() {
		return createIp;
	}

	public void setCreateIp(String createIp) {
		this.createIp = createIp;
	}

	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}

	@Override
	public long idGenerator() {
		ApplicationSettings applicationSettings = Spring.getBean(ApplicationSettings.class);
		long idBase = applicationSettings.getGameServerPlatformid() * 10000 + applicationSettings.getGameServerId();
		// js精确的最大整数是2的53次方，因此玩家ID偏移不能太大
		return idBase << 25;
	}

	public long getChannelId() {
		return channelId;
	}

	public void setChannelId(long channelId) {
		this.channelId = channelId;
	}

	public boolean isCreatePay() {
		return createPay;
	}

	public void setCreatePay(boolean createPay) {
		this.createPay = createPay;
	}

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public long getRecharge() {
		return recharge;
	}

	public void setRecharge(long recharge) {
		this.recharge = recharge;
	}

	public int getVipLevel() {
		return vipLevel;
	}

	public void setVipLevel(int vipLevel) {
		this.vipLevel = vipLevel;
	}

	public String getDeviceModel() {
		return deviceModel;
	}

	public void setDeviceModel(String deviceModel) {
		this.deviceModel = deviceModel;
	}

	public int getPlatformId() {
		return platformId;
	}

	public void setPlatformId(int platformId) {
		this.platformId = platformId;
	}

	public long getFirstPayTime() {
		return firstPayTime;
	}

	public void setFirstPayTime(long firstPayTime) {
		this.firstPayTime = firstPayTime;
	}

	public boolean isNewComer() {
		return newComer;
	}

	public void setNewComer(boolean newComer) {
		this.newComer = newComer;
	}

	public int getHead() {
		return head;
	}

	public void setHead(int head) {
		this.head = head;
	}

	public long getLevel() {
		return level;
	}

	public void setLevel(long level) {
		this.level = level;
	}

	public long getMission() {
		return mission;
	}

	public void setMission(long mission) {
		this.mission = mission;
	}

	@Override
	public long getPlayerId() {
		return id;
	}

	public long getForbidRankTime() {
		return forbidRankTime;
	}

	public void setForbidRankTime(long forbidRankTime) {
		this.forbidRankTime = forbidRankTime;
	}
}
